/**
 * TelephoneValidator.java 
 * Copyright © 2015-3015, 杭州泊享网络科技有限公司
 * 
 * @author Liu Tao
 * @create 2013年10月21日
 */
package com.pshare.framework.validator;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.apache.commons.lang3.StringUtils;

import com.pshare.constant.ReturnMsg;
import com.pshare.constant.SeaxConstants;
import com.pshare.framework.annotation.GpwdCheck;

/**
 * 网关验证密码验证
 */
public class GpwdValidator implements ConstraintValidator<GpwdCheck, String> {

	private static String gpwd = "^\\d{6}$";

	private static Pattern gpwdPattern = Pattern.compile(gpwd);

	@Override
	public void initialize(GpwdCheck constraintAnnotation) {
	}

	@Override
	public boolean isValid(String object, ConstraintValidatorContext constraintContext) {
		if (StringUtils.isBlank(object ))
			return false;

		String input = object.toString().trim().replaceAll(SeaxConstants.BLACKSLASH + SeaxConstants.PLUS, SeaxConstants.BLANK);
		boolean valid = false;
		Matcher	matcher = gpwdPattern.matcher(input);
				if (matcher.matches()) {
					valid = true;
				}
        return valid;
	}
	
}
